/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package de.extra.client.core.builder.impl.plugins;

import javax.inject.Named;
import javax.validation.constraints.NotNull;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import de.drv.dsrv.extrastandard.namespace.plugins.ContactType;
import de.drv.dsrv.extrastandard.namespace.plugins.EndpointType;
import de.drv.dsrv.extrastandard.namespace.plugins.EndpointTypeType;
import de.extra.client.core.annotation.PluginConfigType;
import de.extra.client.core.annotation.PluginConfiguration;
import de.extra.client.core.annotation.PluginValue;
import de.extra.client.core.builder.impl.XmlComplexTypeBuilderAbstr;
import de.extrastandard.api.model.content.IExtraProfileConfiguration;
import de.extrastandard.api.model.content.IInputDataContainer;

/**
 * @author Leonid Potap Die Email Adresse wird aus der Konfiguration gelesen. Es
 *         wird ein SMTP Contact Element erstellt.
 * 
 */
@Named("configurableSMTPContactsPluginsBuilder")
@PluginConfiguration(pluginBeanName = "configurableSMTPContactsPluginsBuilder", pluginType = PluginConfigType.Builder)
public class ConfigurableSMTPContactsPluginsBuilder extends
		XmlComplexTypeBuilderAbstr {

	private static Logger logger = LoggerFactory
			.getLogger(ConfigurableSMTPContactsPluginsBuilder.class);

	private static final String BUILDER_XML_MESSAGE_TYPE = "xplg:Contacts";

	@PluginValue(key = "emailaddress")
	@NotNull
	private String eMailAddress;

	/**
	 * Erstellt den XML Fragment ContactPlugin aus der vorkonfigurierten
	 * Informationen
	 * 
	 */
	@Override
	public Object buildXmlFragment(final IInputDataContainer senderData,
			final IExtraProfileConfiguration config) {
		final ContactType contactType = new ContactType();
		contactType.setUsageHint("USAGE_HINT");
		final EndpointType endpointType = new EndpointType();
		endpointType.setType(EndpointTypeType.SMTP);
		endpointType.setValue(eMailAddress);
		contactType.getEndpoint().add(endpointType);

		logger.debug("ContactTypePlugin created. ");
		return contactType;

	}

	@Override
	public String getXmlType() {
		return BUILDER_XML_MESSAGE_TYPE;
	}

	/**
	 * @param eMailAddress
	 *            the eMailAddress to set
	 */
	public void seteMailAddress(final String eMailAddress) {
		this.eMailAddress = eMailAddress;
	}

}
